package com.java.module.cms.controller.api;

import java.util.List;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.java.common.lang.annotation.ValidateToken;
import com.java.common.lang.domain.page.Page;
import com.java.common.lang.domain.page.PageDomain;
import com.java.common.utils.WebKit;
import com.java.module.cms.domain.About;
import com.java.module.cms.domain.Banner;
import com.java.module.cms.domain.Data;
import com.java.module.cms.domain.Help;
import com.java.module.cms.service.IAboutService;
import com.java.module.cms.service.IBannerService;
import com.java.module.cms.service.IDataService;
import com.java.module.cms.service.IHelpService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 内容管理ApiController
 * 
 * @author Administrator
 */
@ApiSort(200)
@Api(tags = "内容管理")
@RestController("ApiCmsController")
@RequestMapping("/cms")
@ValidateToken(isValidate = false)
public class CmsController {

    private final IAboutService aboutService;

    private final IDataService dataService;

    private final IBannerService bannerService;

    private final IHelpService helpService;

    public CmsController(IAboutService aboutService, IDataService dataService, IBannerService bannerService,
            IHelpService helpService) {
        this.aboutService = aboutService;
        this.dataService = dataService;
        this.bannerService = bannerService;
        this.helpService = helpService;
    }

    @ApiOperationSupport(order = 1)
    @ApiOperation("单篇图文")
    @GetMapping(value = "/about/{id}")
    @ApiImplicitParam(name = "id", value = "单篇图文id", dataTypeClass = Long.class, required = true)
    public About getAbout(@PathVariable("id") Long id) {
        return aboutService.selectAboutById(id);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation("基础数据")
    @GetMapping(value = "/data/{id}")
    @ApiImplicitParam(name = "id", value = "基础数据id", dataTypeClass = Long.class, required = true)
    public Data getDataById(@PathVariable("id") Long id) {
        return dataService.selectDataById(id);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation("轮播图片")
    @GetMapping(value = "/banner/{type}")
    @ApiImplicitParam(name = "type", value = "轮播图片类型", dataTypeClass = Integer.class, required = true)
    public List<Banner> getBannerList(@PathVariable("type") Integer type) {
        return bannerService.selectBannerListByType(type);
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation("帮助中心")
    @GetMapping("/help/list")
    public Page<Help> getHelpList(@Validated PageDomain page) {
        return WebKit.getPageData(() -> helpService.getHelpList());
    }

    @ApiOperationSupport(order = 5)
    @ApiOperation("帮助详情")
    @GetMapping("/help/{id}")
    @ApiImplicitParam(name = "id", value = "帮助ID", dataTypeClass = Long.class, required = true)
    public Help getHelpById(@PathVariable("id") Long id) {
        return helpService.selectHelpById(id);
    }

}